package com.dycn.controller;

import com.dycn.model.SysUser;
import com.dycn.util.AppResultData;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("user")
public class UserController {

    @RequestMapping("login")
    public String login() {
        return "login";
    }

    @RequestMapping("index")
    public String index() {
        return "index";
    }
    @PostMapping("login.json")
    @ResponseBody
    public AppResultData login(SysUser sysUser){
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken token = new UsernamePasswordToken(sysUser.getPhone(), sysUser.getPassword());
        // token.setRememberMe(true);
        subject.login(token);
        return  AppResultData.success("成功","");
    }

}
